package com.bandit.controller;

import com.bandit.pojo.Blog;
import com.bandit.pojo.BlogDate;
import com.bandit.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;

@Controller
public class ViewController {

    @Autowired
    BlogService blogService;

    //去登录界面
    @RequestMapping("/toLogin")
    public ModelAndView toLogin(ModelAndView mv){
        mv.setViewName("forward:/WEB-INF/jsp/login.jsp");
        return mv;
    }

    //去详情界面交给IndexController


    //去标签页交给BlogController


    //去首页交给IndexController


    //去归档
    @RequestMapping("/toPigeonhole")
    public ModelAndView toPigeonhole(ModelAndView mv){
        HashMap<Object, Object> map = new HashMap<>();
        //年和月列表
        List<BlogDate> dateList = blogService.getYearAndMonth();
        for (BlogDate blogDate : dateList) {
            //年和月对应的博客列表
            List<Blog> blogList = blogService.getBlogByDate(blogDate);
            String date = blogDate.getYear() + "年" + blogDate.getMonth() + "月";
            map.put(date,blogList);
            mv.addObject("DateInfo",map);
        }
        mv.setViewName("forward:/WEB-INF/jsp/pigeonhole.jsp");
        return mv;
    }

    //去关于（更新日志）
    @RequestMapping("/toAbout")
    public ModelAndView toAbout(ModelAndView mv){
        mv.setViewName("forward:/WEB-INF/jsp/about.jsp");
        return mv;
    }

    //去后端交给BlogController
}
